import axios from 'axios';

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api';

/**
 * 获取所有班级列表
 * @param {Object} params - 查询参数 { grade, keyword }
 * @returns {Promise}
 */
export const getClasses = (params = {}) => {
  return axios.get(`${API_BASE_URL}/classes`, { params });
};

/**
 * 获取年级列表
 * @returns {Promise}
 */
export const getGrades = () => {
  return axios.get(`${API_BASE_URL}/classes/filter/grades`);
};

/**
 * 获取单个班级详情
 * @param {String} id - 班级ID
 * @returns {Promise}
 */
export const getClass = (id) => {
  return axios.get(`${API_BASE_URL}/classes/${id}`);
};

/**
 * 创建新班级
 * @param {Object} data - 班级数据
 * @returns {Promise}
 */
export const createClass = (data) => {
  return axios.post(`${API_BASE_URL}/classes`, data);
};

/**
 * 更新班级信息
 * @param {String} id - 班级ID
 * @param {Object} data - 更新的数据
 * @returns {Promise}
 */
export const updateClass = (id, data) => {
  return axios.put(`${API_BASE_URL}/classes/${id}`, data);
};

/**
 * 删除班级
 * @param {String} id - 班级ID
 * @returns {Promise}
 */
export const deleteClass = (id) => {
  return axios.delete(`${API_BASE_URL}/classes/${id}`);
};

/**
 * 获取班级统计信息
 * @param {String} id - 班级ID
 * @returns {Promise}
 */
export const getClassStatistics = (id) => {
  return axios.get(`${API_BASE_URL}/classes/${id}/statistics`);
};

/**
 * 同步学生表中的班级数据到班级管理表
 * @returns {Promise}
 */
export const syncClasses = () => {
  return axios.post(`${API_BASE_URL}/classes/sync`);
};
